﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Common;


public class PigAttack : MonsterAction
{
    public override void Update()
    {
        base.Update();
        process();
    }

    public override void Start()
    {
        base.Start();//need do first

        endTime = .5f;
        startTime = .3f;
        Handle.CrossAnimation(Animation.name, .3f);
    }
    private bool attacked = false;
    private float endTime;
    private float startTime;
    private bool ready = false;
    private void process()
    {
        if (Handle.Dead) return;
        if (ready)
        {
            if (!End && Animation.time >= endTime)
            {
                End = true;
                return;
            }
        }
        else
        {
            if (Animation.time >= startTime) ready = true;
        }
        if (ready && !End)
        {
            if (Define.Mode == GameMode.Teamwork)
            {
                if (!attacked && AppInterface.AvatarModule.IOwner.Collider.bounds.Intersects(Handle.Weapon.bounds))
                {
                    AppInterface.AvatarModule.IOwner.OnBeat(this, UnityEngine.Random.Range(-4, -1), Handle as IUnit, true);
                    attacked = true;
                }
            }
        }
    }
}

